﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

using Model;
using Model.Components;
using FrameWork;
using FrameWork.Components;

namespace FrameWork.web.Web
{
    public partial class TJ : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindDataList();
            }
        }
        public string Get_U_GroupID(int U_GroupID)
        {
            return BusinessFacade.sys_GroupDisp(U_GroupID).G_CName;
        }
        public string Geta(double U_GroupID)
        {
            return U_GroupID.ToString();
         //   return (U_GroupID * 100).ToString() + "%";
        }
        /// <summary>
        /// 绑定数据
        /// </summary>
        private void BindDataList()
        {
          
            int RecordCount;
            QueryParam qp = new QueryParam();
            qp.Where = string.Format("Where G_ParentID =1 and G_Delete=0 ");
            ArrayList lst = BusinessFacade.sys_GroupList(qp, out RecordCount);
            foreach (sys_GroupTable var in lst)
            { 
                int IDX = 0;
            
                string i = BusinessFacade.get_table_fileds("T_TJ","ID","bldw",var.GroupID.ToString());
                if (i == "")
                {
                    T_TJEntity ut = BusinessFacadeModel.T_TJDisp(IDX);

                    ut.bldw = var.GroupID;
                    //总件数
                    ut.zjs = Convert.ToInt32(BusinessFacade.get_table_fileds("T_Web", "count(*)", "XCLDW", var.GroupID.ToString()));
                    //按时办结数
                    ut.asbj = Convert.ToInt32(BusinessFacadeModel.get_table_fileds3("T_Web", "count(*)", "zhuangtai", "办结", "XEndDate", "XTime", "1", "1", "XCLDW", var.GroupID.ToString()));
                    //总办结数
                    ut.zbj = Convert.ToInt32(BusinessFacadeModel.get_table_fileds4("T_Web", "count(*)", "zhuangtai", "办结", "1", "1", "1", "1", "XCLDW", var.GroupID.ToString()));
                    //按时办结率 
                    ut.asbjl = ut.asbj / ut.zjs * 100;
                    //总办结率
                    ut.zbjl = ut.zbj / ut.zjs * 100;
                    ut.my = Convert.ToInt32(BusinessFacadeModel.get_table_fileds4("T_Web", "count(*)", "Pevel", "1", "1", "1", "1", "1", "XCLDW", var.GroupID.ToString()));
                    ut.yb = Convert.ToInt32(BusinessFacadeModel.get_table_fileds4("T_Web", "count(*)", "Pevel", "2", "1", "1", "1", "1", "XCLDW", var.GroupID.ToString()));
                    ut.bmy = Convert.ToInt32(BusinessFacadeModel.get_table_fileds4("T_Web", "count(*)", "Pevel", "3", "1", "1", "1", "1", "XCLDW", var.GroupID.ToString()));
                    ut.nopy = Convert.ToInt32(BusinessFacadeModel.get_table_fileds4("T_Web", "count(*)", "Pevel", "0", "1", "1", "1", "1", "XCLDW", var.GroupID.ToString()));
                    ut.DataTable_Action_ = DataTable_Action.Insert;
                    Int32 rInt = BusinessFacadeModel.T_TJInsertUpdateDelete(ut);
                }
                else
                {
                    IDX = Convert.ToInt16(i);
                    T_TJEntity ut = BusinessFacadeModel.T_TJDisp(IDX);

                    ut.bldw = var.GroupID;
                    //总件数
                    ut.zjs = Convert.ToInt32(BusinessFacade.get_table_fileds("T_Web", "count(*)", "XCLDW", var.GroupID.ToString()));
                    //按时办结数
                    ut.asbj = Convert.ToInt32(BusinessFacadeModel.get_table_fileds3("T_Web", "count(*)", "zhuangtai", "办结", "XEndDate", "XTime", "1", "1", "XCLDW", var.GroupID.ToString()));
                    //总办结数
                    ut.zbj = Convert.ToInt32(BusinessFacadeModel.get_table_fileds4("T_Web", "count(*)", "zhuangtai", "办结", "1", "1", "1", "1", "XCLDW", var.GroupID.ToString()));
                    //按时办结率 
                    ut.asbjl = ut.asbj / ut.zjs * 100;
                    //总办结率
                    ut.zbjl = ut.zbj / ut.zjs * 100;
                    ut.my = Convert.ToInt32(BusinessFacadeModel.get_table_fileds4("T_Web", "count(*)", "Pevel", "1", "1", "1", "1", "1", "XCLDW", var.GroupID.ToString()));
                    ut.yb = Convert.ToInt32(BusinessFacadeModel.get_table_fileds4("T_Web", "count(*)", "Pevel", "2", "1", "1", "1", "1", "XCLDW", var.GroupID.ToString()));
                    ut.bmy = Convert.ToInt32(BusinessFacadeModel.get_table_fileds4("T_Web", "count(*)", "Pevel", "3", "1", "1", "1", "1", "XCLDW", var.GroupID.ToString()));
                    ut.nopy = Convert.ToInt32(BusinessFacadeModel.get_table_fileds4("T_Web", "count(*)", "Pevel", "0", "1", "1", "1", "1", "XCLDW", var.GroupID.ToString()));
                    ut.DataTable_Action_ = DataTable_Action.Update;
                 
                    Int32 rInt = BusinessFacadeModel.T_TJInsertUpdateDelete(ut);
                }
                Bind();

            }
             
        }
        private void Bind()
        {
            QueryParam qp = new QueryParam();
            int RecordCount;
            List<T_TJEntity> lst = BusinessFacadeModel.T_TJList(qp, out RecordCount);
            GridView1.DataSource = lst;
            GridView1.DataBind();
            //this.AspNetPager1.RecordCount = RecordCount;
        }
    }
}